import request from "../utils/request";
const MOUDL_NAME = '/dev-api/advert'

// putStatus：投放状态（BEAUDIT-待审核，PENDING-待投放，SUSPEND-暂停中，PUTTING-投放中，SUSPENDED-被暂停，PUTTED-已完成，FAIL-审核不通过）
const creativityStatus = {
  lable: '状态',
  value: 'creativityStatus',
  arr: [
    {
      value: 'ALL',
      label: '全部'
    },
    {
      value: 'BEAUDIT',
      label: '待审核'
    },
    {
      value: 'PENDING',
      label: '待投放'
    },
    {
      value: 'SUSPEND',
      label: '暂停中'
    },
    {
      value: 'PUTTING',
      label: '投放中'
    },
    {
      value: 'SUSPENDED',
      label: '被暂停'
    },

    {
      value: 'PUTTED',
      label: '已完成'
    },
    {
      value: 'FAIL',
      label: '审核不通过'
    }

  ]

}


export function test(data = {}) {
  return request({
    url: `/dev-api/broadcast/monitor/engine/application/needOpen`,
    method: 'POST',
    data
  })
}



export function adListFn(data = {}) {
  return request({
    url: `${MOUDL_NAME}/space/list`,
    method: 'POST',
    data
  })
}

// 查询推广计划列表
export function planListFn(data = {}) {
  return request({
    url: `${MOUDL_NAME}/plan/list`,
    method: 'POST',
    data
  })
}

// 查询推广计划分页列表
export function planListpageFn(data: object) {
  console.log('data: ', data);
  data = { pageNum: 1, pageSize: 10, ...data }
  return request({
    url: `${MOUDL_NAME}/plan/listForPage`,
    method: 'POST',
    data
  })
}





// 查询推广计划列表(下拉列表)
export function planListSelectedFn() {
  return request({
    url: `${MOUDL_NAME}/plan/listSelected`,
    method: 'POST',
    data: { isFree: 0 }
  })
}

// 获取推广计划详细信息
export function getPlanInfoFn(id: string) {
  return request({
    url: `${MOUDL_NAME}/plan/getInfo/${id}`,
    method: 'GET',
    params: {}
  })
}

// 获取推广目的列表
export function getPurposeListFn(data = {}) {
  return request({
    url: `${MOUDL_NAME}/backend/purpose/list`,
    method: 'POST',
    data
  })
}

// 创建推广计划
export function createPromotionPlan(data: object) {
  return request({
    url: `${MOUDL_NAME}/plan/add`,
    method: 'POST',
    data
  })
}

// 修改推广计划
export function editPromotionPlan(data: object) {
  return request({
    url: `${MOUDL_NAME}/plan/edit`,
    method: 'POST',
    data
  })
}

// 删除推广计划
export function deletePlan(id: string) {
  return request({
    url: `${MOUDL_NAME}/plan/delete`,
    method: 'POST',
    data: { id }
  })
}
// 计划检查是否有创意正在播放
export function checkPlan(id: string) {
  return request({
    url: `${MOUDL_NAME}/plan/checkDelete/${id}`,
    method: 'GET'
  })
}

// 查询广告列表
export function advertListFn(data: object) {
  data = { pageSize: 10, pageNum: 1, ...data }
  return request({
    url: `${MOUDL_NAME}/advert/listForPage`,
    method: 'POST',
    data
  })
}

// 查询广告名称列表
export function advertListName(data = {}) {
  return request({
    url: `${MOUDL_NAME}/advert/listSelected`,
    method: 'POST',
    data
  })
}

// 筛选广告的项合并为数组
// export async function filteradsArr() {
//   return [{ lable: '状态',
//     value: 'planStatus', arr: status.arr }, await advertListName(), await planListNameSelectedFn()]
// }



// 查询创意列表
export function creativityListForPageFn(data: object) {
  data = { pageSize: 10, pageNum: 1, ...data }
  return request({
    url: `${MOUDL_NAME}/creativity/listForPage`,
    method: 'POST',
    data
  })
}

// 查询创意列表名称

export function creativityListSelFn(data: object) {
  return request({
    url: `${MOUDL_NAME}/creativity/list`,
    method: 'POST',
    data
  })
}



// 创意开关
export function creativitySwitch(data: object) {
  return request({
    url: `${MOUDL_NAME}/creativity/creativitySwitch`,
    method: 'POST',
    data
  })
}



// 查询广告版面列表及广告位
export function listAndSpaceFn(data: Object) {
  return request({
    url: `${MOUDL_NAME}/pages/listAndSpace`,
    method: 'POST',
    data: {
      ...data, 'advertPagesSpace': {
        'auditStatus': 'PASSED'
      }
    }
  })
}



// 查询广告列表(下拉列表)
export function advertListSelFn() {
  return request({
    url: `${MOUDL_NAME}/advert/listSelected`,
    method: 'POST'
  })
}
// 广告服务：查询广告组合条件（售卖方式、计费模式）
export function listAdvertVoByIdsFn(data: object) {
  return request({
    url: `${MOUDL_NAME}/backend/pages/space/getInfoByIds`,
    method: 'POST',
    data
  })
}

// 保存广告
export function advertAdd(data: object) {
  return request({
    url: `${MOUDL_NAME}/advert/add`,
    method: 'POST',
    data
  })
}

// 查询可用的付费模式
export function listEnableSpace() {
  return request({
    url: `${MOUDL_NAME}/backend/pages/space/list`,
    method: 'POST'
  })
}

// 广告创意分组统计
export function listCreativityGroup() {
  return request({
    url: `${MOUDL_NAME}/creativity/listCreativityGroup/`,
    method: 'POST'
  })
}

// 最近广告播放统计
export function listAdvertLately(rows = 6) {
  return request({
    url: `${MOUDL_NAME}/advert/listAdvertLately/${rows}`,
    method: 'GET'
  })
}

// 获取广告详情信息
export function getADInfo(id: string) {
  return request({
    url: `${MOUDL_NAME}/advert/getInfoByIds`,
    method: 'POST',
    data: { advertIds: [id] }
  })
}

// 获取广告创意信息详情
export function getCreativityInfo(id: string) {
  return request({
    url: `${MOUDL_NAME}/creativity/getInfoById/${id}`,
    method: 'GET'
  })
}

// 创意图片预览
export function creativityPreview(id: string) {
  return request({
    url: `${MOUDL_NAME}/backend/creativity/preview/${id}`,
    method: 'GET'
  })
}

// 新增广告和创意
export function addAdvertAndCreativity(data: object) {
  return request({
    url: `${MOUDL_NAME}/creativity/addAdvertAndCreativity`,
    method: 'POST',
    data
  })
}

// 编辑广告
export function editAd(data: object) {
  return request({
    url: `${MOUDL_NAME}/advert/edit`,
    method: 'POST',
    data
  })
}

// 复制广告
export function copyAd(data: object) {
  return request({
    url: `${MOUDL_NAME}/advert/copy`,
    method: 'POST',
    data
  })
}

// 删除广告
export function delAdvert(id: string) {
  return request({
    url: `${MOUDL_NAME}/advert/delete`,
    method: 'POST',
    data: { id }
  })
}

// 广告检查是否有创意正在播放
export function checkAdvert(id: string) {
  return request({
    url: `${MOUDL_NAME}/advert/checkDelete/${id}`,
    method: 'GET'
  })
}



// 新增广告创意
export function creativityAdd(data: object) {
  return request({
    url: `${MOUDL_NAME}/creativity/add`,
    method: 'POST',
    data
  })
}
// 修改广告创意
export function creativityEdit(data: object) {
  return request({
    url: `${MOUDL_NAME}/creativity/edit`,
    method: 'POST',
    data
  })
}

// 复制创意
export function creativityCopy(data: object) {
  return request({
    url: `${MOUDL_NAME}/creativity/copy`,
    method: 'POST',
    data
  })
}

// 删除创意
export function creativityDel(data: object) {
  return request({
    url: `${MOUDL_NAME}/creativity/delete`,
    method: 'POST',
    data
  })
}

// 创建广告和计划
export function addAdvertAndPlanAndCreativityFn(data: object) {
  return request({
    url: `${MOUDL_NAME}/creativity/addAdvertAndPlanAndCreativity`,
    method: 'POST',
    data
  })
}

// 创建广告和计划
export function addAdvertAndPlanFn(data: object) {
  return request({
    url: `${MOUDL_NAME}/advert/addAdvertAndPlan`,
    method: 'POST',
    data
  })
}

// 查询创意列表
export function creativityList(data: object) {
  data = { pageNum: 1, pageSize: 10, ...data }
  return request({
    url: `${MOUDL_NAME}/creativity/page`,
    method: 'POST',
    data
  })
}

// LBS的范围
export function lbsrange() {
  return request({
    url: `${MOUDL_NAME}/space/config/LBS`,
    method: 'GET',
    params: {}
  })
}


// 查询推广计划目的列表
export async function purposeQuerySelected(data = {}) {
  const res: any = await request({
    url: `${MOUDL_NAME}/backend/purpose/list`,
    method: 'POST',
    data
  })
  return [
    {
      value: 'ALL',
      label: '全部'
    },
    ...res.map((item: any) => ({ value: item.purposeCode, label: item.purposeName }))
  ]
}